from sys import argv
import random
import time



def find_out_requested_name():
    """ Узнаем указанное имя """

    if len(argv) > 1:
        return argv[1]


def get_list_of_something(something):
    """ Получаем список чего-то """

    list_of_something = []
    data = {
        'name': 'names.txt',
        'surname': 'surnames.txt',
        'rest': 'rest.txt',
        'nickname': 'nicknames.txt',
    }
    file_name = data[something]

    with open(file_name) as file:
        for line in file:
            word = line.strip()
            list_of_something.append(word)

    return list_of_something


def combine_words(words0, words1):
    """ Совмещаем слова """

    choice = [0, 1]
    word0 = random.choice(words0).lower()
    word1 = random.choice(words1).lower()

    if random.choice(choice):
        word = word0 + '_' + word1
    else:
        word = word0 + word1.title()

    word = word + str(random.randint(1000, 10000))
    return word


def get_requested_name(requested_name):
    """ Получаем запрашиваемое имя """

    list_of_names = get_list_of_something('name')

    if requested_name == 'rest':
        additionally = get_list_of_something('rest')
    elif requested_name == 'nickname':
        words = get_list_of_something('nickname')
        return random.choice(words)
    else:
        additionally = get_list_of_something('surname')

    word = combine_words(list_of_names, additionally)
    return word


def show_answer(word):
    """ Показываем ответ """
    
    message = f'\nGenerated name: {word}\n'
    print(message)


def main():
    requested_name = find_out_requested_name()
    requested_name = get_requested_name(requested_name)
    show_answer(requested_name)



if __name__ == '__main__':
    main()
